package com.chery.media.ui.main

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.chery.media.R
import com.chery.media.library.contacts.PathContacts
import com.chery.media.network.model.AppInfoBean
import com.chery.media.network.model.BannerDataBean
import com.youth.banner.adapter.BannerAdapter
import com.youth.banner.util.BannerUtils
import java.io.File

class AppAdapter: BaseQuickAdapter<AppInfoBean, BaseViewHolder>(R.layout.item_app){
    override fun convert(holder: BaseViewHolder, item: AppInfoBean) {
        holder.apply {
//            getView<ImageFilterView>(R.id.appIcon).loadPicture(item.first)
            setImageDrawable(R.id.appIcon, item.appIcon)
            setText(R.id.appName, item.appName)
        }
    }
}


class HomeBannerAdapter(urls: ArrayList<BannerDataBean>) :
    BannerAdapter<BannerDataBean, HomeBannerAdapter.BannerViewHolder>(urls) {

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        return BannerViewHolder(BannerUtils.getView(parent!!, R.layout.item_banner))
    }

    override fun onBindView(holder: BannerViewHolder?, data: BannerDataBean?, position: Int, size: Int) {
        val file = File("${PathContacts.IMG_DOWNLOAD}/banner_${data?.id}.jpg")
        if (file.exists()) {
            holder?.bannerImage?.load(file)
        } else {
            holder?.bannerImage?.load(data?.image)
        }
    }

    inner class BannerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var bannerImage: ImageView = itemView.findViewById(R.id.bannerImage)

    }

}


